######################################################################
#Weapons.py
#
#Purpose:  Module for handling all implementations of weapons, both Marine and 
#   non-Marine.
#Author:  Cody Jackson
#Date:  7/21/06
#
#Copyright 2006 Cody Jackson
#This program is free software; you can redistribute it and/or modify it 
#under the terms of the GNU General Public License as published by the Free 
#Software Foundation; either version 2 of the License, or (at your option) 
#any later version.
#
#This program is distributed in the hope that it will be useful, but 
#WITHOUT ANY WARRANTY; without even the implied warranty of 
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
#General Public License for more details.
#
#You should have received a copy of the GNU General Public License 
#along with this program; if not, write to the Free Software Foundation, 
#Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#----------------------------------------------------------------------
#Version 1.0
#   Initial build
######################################################################

#!/usr/bin/env python
from dice_roller import multiDie

class Weapon:
    """ADT for general weapon data."""
    
    def __init__(self, name):
        """Establish characteristics of a weapon."""
        
        self.category = ""
        self.name = name
        self.mass = 0   #kg
        self.rof = 0 #rate of fire
        self.range = 0  #meters
        self.ammo = 0
        self.damage = 0
        self.recoil = 0
    
    def fireWeapon(self):
        """Decrement remaining ammo and tell when clip is empty."""
        
        if self.ammo > 0:
            self.ammo -= 1
        else: print "Your weapon is empty."

#---Melee weapons---#008000#FFFFFF----------------------------------------------
class Knife(Weapon):
    """Subclass for knives, bayonets, and short sword-like weapons."""
    
    def __init__(self, name):
        self.category = "Melee"
        self.mass = 1
        self.range = 1
        self.damage = multiDie(1,1) - 1 #1d6-1
    
class Spear(Weapon):
    """Subclass for spears, gun-mounted bayonets, etc."""
    
    def __init__(self, name):
        self.category = "Melee"
        self.name = name
        self.mass = 2
        self.range = 1.5
        self.damage = multiDie(1,1) + 2 #1d6+2
    
class Club(Weapon):
    """Subclass for clubs, staffs, saps, and other non-edged weapons."""
    
    def __init__(self, name):
        self.category = "Melee"
        self.name = name
        self.mass = 2
        self.range = 1.5
        self.damage = multiDie(1,1) #1d6
    
class Whip(Weapon):
    """Subclass for whips, chains, flails, and other flexible weapons."""
    
    def __init__(self, name):
        self.category = "Melee"
        self.name = name
        self.mass = 1.5
        self.range = 2
        self.damage = multiDie(1,1) + 1 #1d6+1

#---Projectile firearms---#008000#FFFFFF----------------------------------------
class Pistol(Weapon):
    """Subclass for slug-thrower pistols."""
    
    def __init__(self, name):
        self.category = "Small Arms"
        self.name = name
        self.mass = 1
        self.range = 35
        self.rof = 2
        self.ammo = 15
        self.recoil = 1
        self.damage = multiDie(1,1) + 2 #1d6+2

def test():
    #knife = Knife("Knife")
    #print knife.damage
    #spear = Spear("Spear")
    #print spear.damage
    pistol = Pistol("M9")
    print pistol.ammo
    for bullet in range(0,pistol.ammo):
        pistol.fireWeapon()
        print pistol.ammo

if __name__ == "__main__":
    test()
    
